package org.brisling.listenner.workflow;

import java.util.List;
import java.util.Map;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
/**
 * 
 * <p>Title: AssignListener</p>
 * <p>Description: 流程节点人员关联监听器</p>
 * <p>Company: tongking</p>
 * @author jackson wang
 * @since 1.0
 * @version 1.0
 * @date 2017年4月8日 下午11:31:43
 */
public class AssignListener implements TaskListener{

	/**
	 * 
	 */
	private static final long serialVersionUID = 5378488537100563753L;

	@SuppressWarnings("unchecked")
	public void notify(DelegateTask delegateTask) {
	    // Execute custom identity lookups here

	    // and then for example call following methods:
//	    delegateTask.setAssignee("kermit");
		
		delegateTask.getProcessDefinitionId();
	   
	    Map<String,Object> map = delegateTask.getVariables();
	    //判断是否设置授权组
	    List<String> groups =   (List<String>) map.get("groups");
	    if((groups!=null)&&(!groups.isEmpty())){
	    	delegateTask.addCandidateGroups(groups);
	    }
	    
	    String group = (String) map.get("group");
	    //判断是否设置授权组
	    if((group!=null)&&(group.trim().length()>=0)){
	    	delegateTask.addCandidateGroup(group);
	    }
	    
	    
	    //判断是否设置授权组
	    List<String> users =   (List<String>) map.get("users");
	    if((groups!=null)&&(!groups.isEmpty())){
	    	delegateTask.addCandidateUsers(users);
	    }
	    
	    String user = (String) map.get("user");
	    //判断是否设置授权组
	    if((user!=null)&&(user.trim().length()>=0)){
	    	delegateTask.addCandidateUser(user);
	    }
	  }
}
